//顶部菜单
function NavMenu(){
	MenuSel();
	//阅读
	ReadMenu = '<a href="http://www.youmeiwenzi.com/c/read/prose" title="阅读所有散文">散文</a><a href="http://www.youmeiwenzi.com/c/read/poem" title="阅读所有诗歌">诗歌</a><a href="http://www.youmeiwenzi.com/c/read/novel" title="阅读所有小说">小说</a><a href="http://www.youmeiwenzi.com/c/read/essay" title="阅读所有随笔">随笔</a>'
	NavDropDown(ReadMenu);
}

//菜单中选择当前项
function MenuSel(){
	var m = $("#Menu li");
	var MenuPath = location.pathname.replace("/","");
	if ( MenuPath == "" ){	//首页
		$(m).eq(0).addClass("sel");
		return false;
	}else if ( MenuPath.indexOf("tag") > -1 ){		//标签
		$(m).eq(3).addClass("sel");
		return false;
	}else if ( MenuPath.indexOf("read/essay") > 0 ){	//随笔
		$(m).eq(1).addClass("sel1");
		return false;
	}else if ( MenuPath.indexOf("say") > -1 ){		//絮语
		$(m).eq(4).addClass("sel");
		return false;
	}else if ( MenuPath.indexOf("read") || MenuPath.indexOf("date") > 0 ){	//阅读
		$(m).eq(1).addClass("sel1");
		return false;
	}
}

//导航下拉菜单
function NavDropDown(MenuItem){
	$(".dropdown").each(function(){
		$("<div>" + MenuItem + "</div>").appendTo(this).addClass("dd-item");
		$(this).children("a").hover(
			function(){
				$(this).siblings(".dd-item").show();
			},
			function(){
				$(this).siblings(".dd-item").hide();
			}
		);
		$(this).children(".dd-item").hover(
			function(){
				$(this).show();
				$(this).siblings("a").addClass("this");
			},
			function(){
				$(this).hide();
				$(this).siblings("a").removeClass("this");
			}
		);
	});
}

//搜索条
function SearchBar(){
	var formDom=$("#SearchBar"),inputDom=$("#SearchBar>.inpt");
	var searchtitle = "搜索";
	var tip = "要搜索什么?";
	var searchKey = inputDom.val();
	inputDom.focusin(function(){ formDom.addClass("focus"); });
	inputDom.focusout(function(){ formDom.removeClass("focus"); });
	inputDom.val(searchKey?searchKey:searchtitle);
	inputDom.click(function(){
		if (inputDom.val() == searchtitle || inputDom.val() == tip){
			$(this).select();
		}
	});
	formDom.submit(function(){
		if (inputDom.val() == "" || inputDom.val() == searchtitle || inputDom.val() == tip){
			inputDom.val(tip);
			inputDom.select();
			return false;
		}
	});
}

//固定浮层
(function($){
	$.fn.followDIV = function(options){
		var defaults = {}
		var options = $.extend(defaults,options);
		this.each(function(){
			var obj = $(this), t = obj.offset().top;
			window.onscroll = function(){f(obj,t)};
			window.onresize = function(){f(obj,t)};
			
			function f(obj,t){
				var dst = $(document).scrollTop();
				if(($.browser.msie == true) && ($.browser.version == 6.0)){
					if(dst > t) obj.css({position: "absolute", top: dst - t + 40});
				}else{
					if(dst > t) obj.css({position: "fixed", top: 40});
				}
				if(dst <= t) obj.css({position: "static", top: 40});
			}
		});
	}
})(jQuery);

$(function(){
	//消息
	//$('body').prepend('<div style="font-size:15px;text-align:center;padding:10px 0;font-weight:bolder;color:#FFF;background:#64C9F5;width:880px;margin:20px auto 0 auto;border-radius:10px;">11月16号12点到11月18号12点，优美文字网进行服务器架构升级，届时网站将无法访问，给您造成的不便请谅解！</div>');
	//焦点图
	if ($("#slides").length > 0){
		$("#slides").slides({
			preload: true,
			preloadImage: '/wp-content/themes/txtjee/images/loading.gif',
			play:7000,
			pause:500,
			slideSpeed:800,
			hoverPause:true,
			animationStart:function(current){
				$("#slides .text").animate({bottom:-40},100);
			},animationComplete:function(current){
				$("#slides .text").animate({bottom:0},300);
			},slidesLoaded:function(){
				$("#slides .text").animate({bottom:0},100);
			}
		});
	}
	
	//懒加载
	if (navigator.platform == "iPad") return;
	$("img").not(".cycle img").lazyload({
		effect:"fadeIn",
		placeholder: "/wp-content/themes/txtjee/images/n.gif"
	});
	
	//投稿切换
	$("#Contribute").hover(
		function (){
			$(this).addClass("hov");
		},
		function (){
			$(this).removeClass("hov");
		}
	);

	//返回顶部
	var $backToTopEle = $('<div class="backToTop"><a href="javascript:void(0);"></a></div>').appendTo($("body")).hide().click(function() {
		$("html, body").animate({ scrollTop: 0 }, 300);
	}), $backToTopFun = function() {
		var st = $(document).scrollTop(), winh = $(window).height();
		(st > 600) ? $backToTopEle.fadeIn(100) : $backToTopEle.fadeOut(100);	//滚动600px时才出现	
		//IE6下的定位
		if (!window.XMLHttpRequest) {
			$backToTopEle.css("top", st + winh - 135);	
		}
	};
	$(window).bind("scroll", $backToTopFun);
	$backToTopFun();
});